/**
 * 
 */
package com.kclmedu.forhelp.ui;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Properties;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 * 配置面板
 * @author yejf
 *
 */
public class ConfigPanel extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2768738753250296050L;

	//组件
	private JLabel width;
	private JLabel height;
	private JLabel dir;
	
	private JTextField widthValue;
	private JTextField heightValue;
	
	private JTextField dirValue;
	
	private JButton saveBtn;
	
	private JButton cancelBtn;
	
	public ConfigPanel() {
		//
		setTitle("配置中心");
		setBounds(200, 300, 430, 170);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		
		//初始化组件
		width = new JLabel("列宽:");
		widthValue = new JTextField(1);
		
		height = new JLabel("行高");
		heightValue = new JTextField(1);
		
		dir = new JLabel("导出的默认目录:");
		dirValue = new JTextField(1);
		dirValue.setText("点击选择目录");
		dirValue.setEditable(false);
		dirValue.setBackground(Color.yellow);
		
		saveBtn = new JButton("保存");
		cancelBtn = new JButton("取消");
		//设置 布局
		setLayout(new GridLayout(4, 2));
		//添加组件
		add(width);
		add(widthValue);
		
		add(height);
		add(heightValue);
		
		add(dir);
		add(dirValue);
		
		add(saveBtn);
		add(cancelBtn);
		
		//添加事件
		dirValue.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "单击了文本框");
				
			}
		});
		
		cancelBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				setVisible(false);
			}
		});
		
		//重 点要操作的部份
		saveBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				//读取各个组件的的值，并写入到配置文件中去
				JOptionPane.showMessageDialog(null, "需求不足，此功能暂未实现！");
				//TODO ...
			}
		});
	}
	
	public static void main(String[] args) {
//		ConfigPanel cp = new ConfigPanel();
//		cp.setVisible(true);
		//
		/*for(String env : System.getenv().keySet()) {
			System.out.println(env);
		}
		System.out.println("======================");
		
		Properties props = System.getProperties();
		props.list(System.out);*/
		
		System.out.println(System.getProperty("user.home"));
	}
}
